package com.qianlou.controller;


import com.qianlou.common.result.BaseResponse;
import com.qianlou.pojo.bo.JobBO;
import com.qianlou.service.JobService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/job")
public class JobController {

    @Resource
    private JobService jobService;

    @PostMapping("/createOrUpdate")
    public BaseResponse createOrUpdate(@RequestBody @Valid JobBO jobBO) {
        jobService.createOrUpdate(jobBO);
        return BaseResponse.ok();
    }

    @GetMapping("/list")
    public BaseResponse list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return BaseResponse.ok(jobService.selectJobList(page, pageSize));
    }

    @GetMapping("/delete")
    public BaseResponse delete(@RequestParam(value = "jobId") String jobId) {
        jobService.removeById(jobId);
        return BaseResponse.ok();
    }

    @GetMapping("/detail")
    public BaseResponse detail(@RequestParam(value = "jobId") String jobId) {
        return BaseResponse.ok(jobService.getById(jobId));
    }

    @GetMapping("/nameList")
    public BaseResponse nameList() {
        List<HashMap<String, String>> nameList = jobService.getNameList();
        return BaseResponse.ok(nameList);
    }

}